package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.ProductAttribute;
import com.itheima.mapper.ProductAttributeMapper;
import com.itheima.service.IProductAttributeService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品属性参数表 服务实现类
 * </p>
 *
 * @author fukeke
 * @since 2022-11-11
 */
@DubboService
public class ProductAttributeServiceImpl extends ServiceImpl<ProductAttributeMapper, ProductAttribute> implements IProductAttributeService {
    @Autowired
    ProductAttributeMapper productAttributeMapper;

    @Override
    public ProductAttribute findById(Long id) {
        return productAttributeMapper.selectById(id);
    }

    @Override
    public void create(ProductAttribute productAttribute) {
        productAttributeMapper.insert(productAttribute);
    }

    @Override
    public void deleteAttr(List<Long> attrIds) {
        productAttributeMapper.deleteBatchIds(attrIds);
    }

    @Override
    public PageBeanVo findByCidAndPage(Long cid, Integer pageNum, Integer pageSize, Integer type) {
        //添加查询条件
        LambdaQueryWrapper<ProductAttribute> qw=new LambdaQueryWrapper<>();
        qw.eq(ProductAttribute::getProductAttributeCategoryId,cid).eq(ProductAttribute::getType,type);
        //添加分页条件
        Page<ProductAttribute> page=new Page<>(pageNum,pageSize);

        productAttributeMapper.selectPage(page,qw);

        //封装分页对象并返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());

    }

    @Override
    public void updateAttr(ProductAttribute productAttribute) {
        productAttributeMapper.updateById(productAttribute);
    }
}
